//按钮事件新增或编辑
var BE50BD_type = "";
//其他页面传到本页面参数
var BE50BD_param = {};
//暂时没用
var BE50BD_validate = "";
//当前触发按钮
var BE50BD_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var BE50BD_ary_IS_FILE = [{"MAIN_ID":"0","CN_NAME":"否"},{"MAIN_ID":"1","CN_NAME":"是"}];
var BE50BD_ary_TO_URL_TYPE = [{"MAIN_ID":"-1","CN_NAME":""},{"MAIN_ID":"0","CN_NAME":"系统内弹窗"},{"MAIN_ID":"1","CN_NAME":"系统内tab页"},{"MAIN_ID":"2","CN_NAME":"浏览器窗口"}];

/*declare select options end*/

//输入框默认值
function BE50BD_input_default(){
	//所有输入框设置默认值
	/*Input Default Begin*/
	$("#BE50BD_IS_FILE").val("0");
	$("#BE50BD_TO_URL_TYPE").val("-1");
	/*Input Default End*/
}

//主从表传递参数
function BE50BD_param_set(){
	/*Main Subsuv Table Param Begin*/
    $("#BE50BD_find_COLUMN_ID_cn_name").val("");
    $("#BE50BD_COLUMN_ID").val("-1");
    if(BE50BD_param.hasOwnProperty("COLUMN_ID_cn_name"))
        $("#BE50BD_find_COLUMN_ID_cn_name").val(s_decode(BE50BD_param["COLUMN_ID_cn_name"]));
    if(BE50BD_param.hasOwnProperty("COLUMN_ID"))
        $("#BE50BD_COLUMN_ID").val(BE50BD_param["COLUMN_ID"]);
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function BE50BD_t_column_expand_biz_start(inputdata) {
	BE50BD_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    $.each(BE50BD_ary_IS_FILE, function (i, obj) {
        addOptionValue("BE50BD_IS_FILE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
    });
    $.each(BE50BD_ary_TO_URL_TYPE, function (i, obj) {
        addOptionValue("BE50BD_TO_URL_TYPE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
    });
    BE50BD_init_t_column_expand()
	
    /*biz end*/
}

/*biz step begin*/
function BE50BD_format_IS_FILE(value, row, index) {
    var objResult = value;
    for(i = 0; i < BE50BD_ary_IS_FILE.length; i++) {
        var obj = BE50BD_ary_IS_FILE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function BE50BD_format_TO_URL_TYPE(value, row, index) {
    var objResult = value;
    for(i = 0; i < BE50BD_ary_TO_URL_TYPE.length; i++) {
        var obj = BE50BD_ary_TO_URL_TYPE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}


/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/
function BE50BD_TO_URL_cn_name_fun(){
	BE50BD_btn = "TO_URL"
    index_subhtml = "dev_vue/v_menu_info.vue";
    random_subhtml = "A55264";
    if(loadHtmlSubVueFun("dev_vue/v_menu_info.vue","BE50BD_t_column_expand_call_vue") == true){
        var n = Get_RandomDiv("A55264","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#A55264_v_menu_info_Events').bootstrapTable('resetView');
                A55264_param["ly_index"] = index;
                A55264_param["target_name"] = "BE50BD_TO_URL";
                A12594_param["target_id"] = "BE50BD_TO_URL";
                A12594_param["sourc_id"] = "MENU_URL";
                A55264_param["sourc_name"] = "MENU_URL";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}
/*find qry fun end*/

/*页面结束*/
function BE50BD_page_end(){
	page_btn_priv("BE50BD");
	BE50BD_get_by_db();
}

//页面初始化方法
function BE50BD_init_t_column_expand() {
	//输入框默认值
	BE50BD_input_default();
	//参数传递
	BE50BD_param_set();	
	//表单验证
	BE50BD_checkFormInput();
	//结束函数
	BE50BD_page_end();
}

//提交表单数据
function BE50BD_SubmitForm(){
	if($("#BE50BD_MAIN_ID").val() == ""){
		var inputdata = {
				"param_name": "N01_ins_t_column_expand",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": s_encode($("#BE50BD_IS_FILE").val())
                ,"param_value2": s_encode($("#BE50BD_TO_URL").val())
                ,"param_value3": $("#BE50BD_TO_URL_TYPE").val()
                ,"param_value4": s_encode($("#BE50BD_TO_URL_PARAM").val())
                ,"param_value5": $("#BE50BD_COLUMN_ID").val()
                ,"param_value6": $("#BE50BD_DEFAULT_VALUE").val()
                
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "BE50BD_get_N01_ins_t_column_expand");
	}
	else{
		var inputdata = {
				"param_name": "N01_upd_t_column_expand",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": s_encode($("#BE50BD_IS_FILE").val())
                ,"param_value2": s_encode($("#BE50BD_TO_URL").val())
                ,"param_value3": $("#BE50BD_TO_URL_TYPE").val()
                ,"param_value4": s_encode($("#BE50BD_TO_URL_PARAM").val())
                ,"param_value5": $("#BE50BD_COLUMN_ID").val()
                ,"param_value6": $("#BE50BD_DEFAULT_VALUE").val()
                ,"param_value7": $("#BE50BD_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "BE50BD_get_N01_upd_t_column_expand");
	}
}

//vue回调
function BE50BD_t_column_expand_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
	else if(index_subhtml == "dev_vue/v_menu_info.vue"){
        var n = Get_RandomDiv("A55264",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":BE50BD_type,
                    "ly_index":index,
                    "target_name":"BE50BD_find_TO_URL_cn_name",
                    "target_id":"BE50BD_TO_URL",
                    "sourc_id":"MENU_URL",
                    "sourc_name":"MENU_URL"
                };
                loadScript_hasparam("dev_vue/v_menu_info.js","A55264_v_menu_info_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
	/*get find subvue end*/
}

//for表单提交
$("#BE50BD_save_t_column_expand_Edit").click(function () {
	$("form[name='BE50BD_DataModal']").submit();
})

/*修改数据*/
function BE50BD_get_N01_upd_t_column_expand(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_column_expand) == true)
	{
		swal("修改数据成功!", "", "success");
		BE50BD_clear_validate();
		layer.close(BE50BD_param["ly_index"]);
	}
}

/*添加数据*/
function BE50BD_get_N01_ins_t_column_expand(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_column_expand) == true)
	{
		swal("添加数据成功!", "", "success");
		BE50BD_clear_validate();
		layer.close(BE50BD_param["ly_index"]);
	}
}

//取消编辑
$("#BE50BD_cancel_t_column_expand_Edit").click(function () {
	layer.close(BE50BD_param["ly_index"]);
	BE50BD_clear_validate();
	$("[id^='BE50BD_div']").hide();
})

//清除查找框
function BE50BD_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function BE50BD_clear_validate(){
	$("#BE50BD_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#BE50BD_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#BE50BD_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function BE50BD_clear_edit_info(){
	var inputs = $("#BE50BD_DataModal").find('input');
	var selects = $("#BE50BD_DataModal").find("select");
	var textareas = $("#BE50BD_DataModal").find('textarea');
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
	
	/*input validate clear end*/
	BE50BD_init_t_column_expand();
}

//从接口中获取数据并绑定
function BE50BD_get_by_db(){
	//以下为特殊字段列表查询，无特殊字段时不需要
	var inputdata = {
		"param_name": "N01_sel_t_column_expand_ByID",
		"session_id": session_id,
		"login_id": login_id
		/*传递查询条件变量*/
        /*get query param begin*/

        ,"param_value1": BE50BD_param["COLUMN_ID"]	
        /*get query param end*/
	};
	ly_index = layer.load();
	get_ajax_baseurl(inputdata, "BE50BD_N01_sel_t_column_expand_ByID");
}

//获取接口数据并绑定
function BE50BD_N01_sel_t_column_expand_ByID(input){
	layer.close(ly_index);
	//查询失败
    if (Call_QryResult(input.N01_sel_t_column_expand_ByID) == false)
        return false;
    else if(input.N01_sel_t_column_expand_ByID.length > 0){
    	var rowData = input.N01_sel_t_column_expand_ByID[0];
    	var inputs = $("#BE50BD_DataModal").find('input');
    	var selects = $("#BE50BD_DataModal").find("select");
    	var textareas = $("#BE50BD_DataModal").find('textarea');
		//通用子页面输入框赋值
		Com_edit_info(rowData,inputs,selects,textareas,"BE50BD","BE50BD");
    }
}

//页面输入框赋值
function BE50BD_get_edit_info(){
	var rowData = $("#AE50BD_t_column_expand_Events").bootstrapTable('getData')[AE50BD_select_t_column_expand_rowId];
	var inputs = $("#BE50BD_DataModal").find('input');
	var selects = $("#BE50BD_DataModal").find("select");
	var textareas = $("#BE50BD_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"AE50BD","BE50BD");
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function BE50BD_checkFormInput() {
    BE50BD_validate = $("#BE50BD_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            BE50BD_MAIN_ID: {}
            ,BE50BD_IS_FILE: {maxlength:50}
            ,BE50BD_TO_URL: {maxlength:200}
            ,BE50BD_TO_URL_TYPE: {}
            ,BE50BD_TO_URL_PARAM: {maxlength:2000}
            ,BE50BD_COLUMN_ID: {digits: true,required : true,maxlength:10}
            ,BE50BD_DEFAULT_VALUE: {maxlength:500}
            
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            BE50BD_MAIN_ID: {}
            ,BE50BD_IS_FILE: {maxlength:"长度不能超过50"}
            ,BE50BD_TO_URL: {maxlength:"长度不能超过200"}
            ,BE50BD_TO_URL_TYPE: {}
            ,BE50BD_TO_URL_PARAM: {maxlength:"长度不能超过2000"}
            ,BE50BD_COLUMN_ID: {digits: "必须输入整数",required : "必须输入整数",maxlength:"长度不能超过10" }
            ,BE50BD_DEFAULT_VALUE: {maxlength:"长度不能超过200"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	BE50BD_SubmitForm();
        	return false;
        }
    })
}